class RadgrouprepliesController < ApplicationController
  before_action :set_radgroupreply, only: [:show, :edit, :update, :destroy]
  before_action :set_group, only: [:index, :new, :create, :edit]

  # GET /radgroupreplies
  # GET /radgroupreplies.json
  def index
    @radgroupreplies = @group.radgroupreplies.all
  end

  # GET /radgroupreplies/1
  # GET /radgroupreplies/1.json
  def show
    @group_id = params[:group_id]
  end

  # GET /radgroupreplies/new
  def new
    @radgroupreply = Radgroupreply.new
  end

  # GET /radgroupreplies/1/edit
  def edit
  end

  # POST /radgroupreplies
  # POST /radgroupreplies.json
  def create
    @radgroupreply = @group.radgroupreplies.new(radgroupreply_params)
    @radgroupreply.groupname = @group.name

    respond_to do |format|
      if @radgroupreply.save
        format.html { redirect_to [@group, @radgroupreply], notice: 'Radgroupreply was successfully created.' }
        format.json { render action: 'show', status: :created, location: @radgroupreply }
      else
        format.html { render action: 'new' }
        format.json { render json: @radgroupreply.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /radgroupreplies/1
  # PATCH/PUT /radgroupreplies/1.json
  def update
    respond_to do |format|
      if @radgroupreply.update(radgroupreply_params)
        format.html { redirect_to group_radgroupreply_path(params[:group_id], @radgroupreply), notice: 'Radgroupreply was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: 'edit' }
        format.json { render json: @radgroupreply.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /radgroupreplies/1
  # DELETE /radgroupreplies/1.json
  def destroy
    @radgroupreply.destroy
    respond_to do |format|
      format.html { redirect_to group_radgroupreplies_url(params[:group_id]) }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_radgroupreply
      @radgroupreply = Radgroupreply.find(params[:id])
    end

    def set_group
      @group = Group.find(params[:group_id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def radgroupreply_params
      params.require(:radgroupreply).permit(:group_id, :groupname, :attr, :op, :value)
    end
end
